//
//  DetailPostViewController.m
//  FlowerRainGround
//
//  Created by zfc on 16/4/20.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "DetailPostViewController.h"
#import "MyPostCollectionView.h"



@interface DetailPostViewController ()

@end

@implementation DetailPostViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    

    NSLog(@"詹富财贼帅！！！");

    
    NSLog(@"詹FC");
    self.model = self.recommendArray[_index];
    MyPostCollectionView *view = [[MyPostCollectionView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [view createPostCollectionViewWithModel:self.model];
    
    [self.view addSubview:view];
    
}

/*
- (void)createCollection {
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    _imagewidth = (kWidth - 24) / 3;
    layout.itemSize = CGSizeMake(_imagewidth, _imagewidth);
    layout.sectionInset = UIEdgeInsetsMake(0, 10, 0, 10);
    layout.minimumLineSpacing = 2;
    layout.minimumInteritemSpacing = 2;
//    layout.headerReferenceSize = CGSizeMake(kWidth, kHeight * 2 / 3);

    
//    NSInteger number = [self getRowNumber];
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight) collectionViewLayout:layout];
    
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.bounces = YES;
    [_collectionView registerNib:[UINib nibWithNibName:@"PicCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"zz"];
    [self.collectionView registerClass:[HeaderCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    [self.collectionView registerClass:[FooterCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
//    [self.collectionView registerNib:[UINib nibWithNibName:@"FooterCollectionReusableView" bundle:nil] forCellWithReuseIdentifier:@"footer"];
}

//获取列数
- (NSInteger)getRowNumber {
    
    if (self.picArray.count % 3 == 0) {
        return self.picArray.count / 3;
    } else {
        return self.picArray.count / 3 + 1;
    }
}



#pragma mark --- 集合视图代理方法 ---

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.picArray.count;
}

- (UICollectionViewCell *)
collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    PicCollectionVeiwCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"zz" forIndexPath:indexPath];
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:self.picArray[indexPath.row]]];
    

    return cell;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    if ([kind isEqual:UICollectionElementKindSectionHeader]) {
        HeaderCollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:indexPath];
        
        PicHeaderView *h = [PicHeaderView headerView];
        h.frame = headerView.frame;
        [headerView addSubview:h];
        [h.headImg sd_setImageWithURL:[NSURL URLWithString:self.model.customerModel.headImg]];
        h.userNameLabel.text = self.model.customerModel.userName;
        h.contentLabel.text = self.model.customerModel.content;
        h.createDataLabel.text = self.model.customerModel.createDate;
        
        
        return headerView;
//       return [HeaderCollectionReusableView headerView];
    } else {

        FooterCollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:indexPath];

        PicFooterView *p = [PicFooterView footerView];
        p.frame = CGRectMake(0, 0, kWidth, 80);
        [footerView addSubview:p];
        NSLog(@"%@", self.model);
        
        p.contentLabel.text = self.model.content;
        p.commentLabel.text = [NSString stringWithFormat:@"%@",self.model.comment];
        p.shareLabel.text = [NSString stringWithFormat:@"%@",self.model.share];
        p.appointLabel.text = [NSString stringWithFormat:@"%@",self.model.appoint];

        NSLog(@"1%@",[self.model.content class]);
        NSLog(@"2%@",[self.model.comment class]);

        NSLog(@"3%@",[self.model.share class]);

        NSLog(@"4%@",[self.model.appoint class]);

       
        return footerView;
    }
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    return CGSizeMake(kWidth, kHeight - (84 + _imagewidth * 3));
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(kWidth, 80);

}

*/

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
